//
//  MessageSendViewController.m
//  ForengnMenu
//
//  Created by @-@ on 16/1/19.
//  Copyright © 2016年 余旺. All rights reserved.
//

#import "MessageSendViewController.h"
#import "MessageSendView.h"
//#import "BubbleView.h"


@interface MessageSendViewController ()

@property MessageSendView * sendView;

//@property BubbleView * bubbleView;

@end

@implementation MessageSendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.bubbleView = [[BubbleView alloc] initWithFrame:CGRectMake(100, 100, 150, 150)];
//    
//    self.bubbleView.bubbleImageView.image = [UIImage imageNamed:@"bubble.png"];
//    
//    self.bubbleView.contentLabel.text = @"Copyright © 2016年 余旺. All rights reserved.";
//    
//    self.bubbleView.contentLabel.textColor = [UIColor whiteColor];
//    
//    [self.view addSubview:self.bubbleView];
    
    

    //去目录加载xib文件
    self.sendView = [[[NSBundle mainBundle] loadNibNamed:@"MessageSendView" owner:self options:nil] lastObject];
    
    CGRect rect = self.sendView.frame;
    
    //在o-c里面如果类的属性为结构体，那么我们不能够直接去修改这个结构体属性内部的变量。我们只有访问的权限{get}
    rect.origin.y = self.view.frame.size.height - self.sendView.frame.size.height;
    
    self.sendView.frame = rect;
    
    
    //添加到当前视图
    [self.view addSubview:self.sendView];
    
    
    //键盘发送变化的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];


}

//实现键盘的通知
-(void)KeyboardWillChange:(NSNotification *)notification{
    //拿到键盘的信息
    NSDictionary * dic = notification.userInfo;
    
    //键盘的frame
    CGRect rect = [dic[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    float y = rect.origin.y - self.sendView.frame.size.height;
    
    CGRect sendRect = self.sendView.frame;
    
    sendRect.origin.y = y;
    
    self.sendView.frame = sendRect;
    
}

//触摸结束时触发
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
    
}



@end
